package com.foreveross.chameleon.manager;

import java.util.HashMap;
import java.util.Map;

import com.foreveross.chameleon.model.ModuleInfo;



public class AutoDownloadHelper {


		private static AutoDownloadHelper instance;
		
		//当前自动下载的任务列表
		private static Map<String,ModuleInfo> downloadList = new HashMap<String, ModuleInfo>();
		
		//当前自动下载的任务列表
		private static Map<String,ModuleInfo> totalList = new HashMap<String, ModuleInfo>();
		
//		//自动下载的总数
//		private static int autoDownloadCount = 0;
		
		
		
		

		/**
		 * @return
		 */
		public static AutoDownloadHelper getInstance(){
			if(instance ==null){
				instance = new AutoDownloadHelper();
			}
			return instance;
		}
		
//		public static int getAutoDownloadCount() {
//			return autoDownloadCount;
//		}
	//	
//		//设置自动下载任务的总数
//		public void setAutoDownloadCount(int autoDownloadCount) {
//			AutoDownloadHelper.autoDownloadCount = autoDownloadCount;
//		}
		
		public int getProgressCount(){
			return downloadList.size();
		}
		
		public int getTotalCount(){
			return totalList.size();
		}
		
		public boolean addDownloadTask(ModuleInfo module){
			boolean isSuccess = false;
			if(!downloadList.containsKey(module.getIdentifier())){
				synchronized (downloadList) {
					downloadList.put( module.getIdentifier() , module);
					isSuccess=true;
				}
			}else{
				isSuccess=false;
			}
			
			if(!totalList.containsKey(module.getIdentifier())){
				synchronized (totalList) {
					totalList.put( module.getIdentifier() , module);
					isSuccess=true;
				}
			}else{
				isSuccess=false;
			}
			return isSuccess;
		}
		
		public void finishDownload(ModuleInfo module){
			if(downloadList.containsKey(module.getIdentifier())){
				synchronized (downloadList) {
					downloadList.remove(module.getIdentifier());
				}
			}
			
		}
		
		public void clear(){
			synchronized (downloadList) {
				downloadList.clear();
//				autoDownloadCount=0;
				totalList.clear();
			}
		}
}

